package com.application.tourapp;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;

import com.application.tourapp.async.MainLoaderAsyncActivity;
import com.application.tourapp.global.TourAppGlobal;

/**
 * L'activite qui demare tout
 * 
 * @author Ramy
 * 
 */

@SuppressLint("SdCardPath")
@SuppressWarnings("deprecation")
public class StarterActivity extends GenericActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		AlertDialog alertDialog = new AlertDialog.Builder(StarterActivity.this)
				.create();
		alertDialog.setTitle("Connexion");
		alertDialog
				.setMessage("Pour ce premier lancement de l'application, il vous faut un accès à internet");
		alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				finish();
			}
		});
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.starter_activity);

		SQLiteDatabase checkDatabase = null;
		try {
			checkDatabase = SQLiteDatabase.openDatabase(
					"/data/data/com.application.tourapp/databases/tourapp",
					null, SQLiteDatabase.OPEN_READONLY);
		} catch (SQLiteException e) {
			checkDatabase = null;
		}
		if (!TourAppGlobal.isOnline(this) && checkDatabase == null) {
			alertDialog.show();
		} else {
			if (TourAppGlobal.isOnline(this)) {
				TourAppGlobal.IS_CONNECT = true;
			}
			new MainLoaderAsyncActivity(this).execute();
		}

	}

}
